package ace.module.account.sdk.core.impl;

import ace.cmp.core.model.R;
import ace.cmp.json.api.JsonService;
import ace.module.account.api.IamAuthenticationApi;
import ace.module.account.api.model.auth.dto.AuthenticationResult;
import ace.module.account.api.model.auth.input.AuthenticationInputMap;
import ace.module.account.api.model.auth.input.AuthenticationParams;
import ace.module.account.api.model.auth.input.GenericAuthenticationInput;
import ace.module.account.sdk.core.feign.impl.IamAuthenticationFeign;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

@AllArgsConstructor
@Slf4j
@Component
public class IamAuthenticationApiImpl implements IamAuthenticationApi {
  private final IamAuthenticationFeign iamAuthenticationFeign;
  private final JsonService jsonService;

  @Override
  public <TParams extends AuthenticationParams> R<AuthenticationResult> authentication(
      GenericAuthenticationInput<TParams> input) {
    String json = jsonService.toJson(input);
    return iamAuthenticationFeign.authentication(json);
  }

  @Override
  public R<AuthenticationResult> authentication(AuthenticationInputMap input) {
    return authentication((GenericAuthenticationInput<? extends AuthenticationParams>) input);
  }
}
